package learn.netty.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import learn.netty.server.handler.DiscardServerHandler;

import java.nio.ByteBuffer;

/**
 * @USER white
 * @DATETIME 2020/10/14 20:33
 */
public class NettyServer {
    private int port;

    public NettyServer(int port) {
        this.port = port;
    }

    public void start() throws InterruptedException {
        NioEventLoopGroup bossGroup = new NioEventLoopGroup();
        NioEventLoopGroup workerGroup = new NioEventLoopGroup();

        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup,workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new DiscardServerHandler());

        ChannelFuture future = serverBootstrap.bind(9011).sync();
        //关闭服务
        future.channel().closeFuture().sync();


    }

}
